class Animal{
    String name;
    int age;
    public Animal(String name, int age){
        this.name = name;
        this.age = age;
    }
    public void eat(){
        System.out.println("吃饭");
    }
    public void sleep(){
        System.out.println("睡觉");
    }
}

class Cat extends Animal{
    public Cat (String name, int age){
        super(name, age);
    }
    public void eat(){
        System.out.println("吃鱼");
    }
    public void mew(){
        System.out.println("maiomiao");
    }
}

class Dog extends Animal{
    public Dog(String name, int age){
        super(name, age);
    }
    public void eat(){
        System.out.println("吃骨头");
    }
    public void bark(){
        System.out.println("wangwang");
    }
}

public class TestDemo2 {
    public static void main(String[] args) {
        Cat cat = new Cat("yuanbao", 2);
        Dog dog = new Dog("xiaoqi", 1);

        Animal animal = cat;
        animal.eat();

        animal = dog;
        animal.eat();

        if(animal instanceof Cat){
            cat = (Cat)animal;
            cat.mew();
        }

        if(animal instanceof Dog){
            dog = (Dog)animal;
            dog.bark();
        }
    }
}
